Sort help strings on output to make them slightly less incomprehensible. :-)
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 26 Jun 2004 04:55:35 +0000 (04:55 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 26 Jun 2004 04:55:35 +0000 (04:55 +0000)
gpsbabel/Makefile
gpsbabel/internal_styles.c
gpsbabel/mkstyle.sh
gpsbabel/vecs.c

index fa87d7eb0f46014c09d886386f3d1cf8ae438519..c7907116994885757497e4b9b4203690b86f0815 100644 (file)
@@ -243,4 +243,4 @@ jeeps/gpsutil.o: jeeps/gpsutil.c jeeps/gps.h defs.h queue.h \
   jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h jeeps/gpsnmeafmt.h \
   jeeps/gpsnmeaget.h
 internal_styles.c: mkstyle.sh style/README.style style/arc.style style/csv.style style/custom.style style/dna.style style/fugawi.style style/gpsdrive.style style/gpsman.style style/mapconverter.style style/mxf.style style/nima.style style/s_and_t.style style/saplus.style style/tabsep.style style/xmap.style style/xmapwpt.style
-       ./mkstyle.sh > internal_sytles.c || (rm -f dep ; exit 1)
+       ./mkstyle.sh > internal_styles.c || (rm -f dep ; exit 1)
index e7e046b6ee8551125244904c3c678b100ee73b4b..ab5bc6143c605210d962b985b035687054027cab 100644 (file)
@@ -555,3 +555,4 @@ static char xmapwpt[] =
 ;
 #include "defs.h"
 style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "tabsep", tabsep } , { "saplus", saplus } , { "s_and_t", s_and_t } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } ,  {0,0}};
+size_t nstyles = 15;
index 52c799a5c37dbe1e040ff4827f0ef8aa197b939e..418e60f05052ca4046fa7c33512019dcc80951ab 100755 (executable)
@@ -3,6 +3,7 @@ echo "/* This file is machine-generated from the contents of style/ */"
 echo "/* by mkstyle.sh.   Editing it by hand is an exeedingly bad idea. */"
 echo 
 
+nstyles="0"
 for i in style/*.style
 do
        A=`basename $i | sed "s/.style$//"`
@@ -12,8 +13,9 @@ do
        echo "static char $A[] = "
        sed 's/\\/\\\\/;s/"/\\"/g;s/\(^.\)/"\1/g;s/\(.$\)/\1\\n"/g' $i
        echo ";"
-
+       nstyles=`expr $nstyles + 1`;
 done
 
 echo "#include \"defs.h\""
 echo "style_vecs_t style_list[] = {$ALIST {0,0}};"
+echo "size_t nstyles = $nstyles;"
index 0fc7ee4de67f0a9164ee9aaf07b55ff64ae63307..1bb62affb22f647b4dfd26b86be8d398c5b99675 100644 (file)
@@ -411,32 +411,61 @@ get_option(const char *iarglist, const char *argname)
  *  Display the available formats in a format that's easy for humans to
  *  parse for help on available command line options.
  */
+static signed int 
+alpha (const void *a, const void *b)
+{
+
+       const vecs_t *const *ap = a;
+       const vecs_t *const *bp = b;
+       
+       return strcmp((*ap)->name , (*bp)->name);
+}
+
 void
 disp_vecs(void)
 {
        vecs_t *vec;
        style_vecs_t *svec;
        arglist_t *ap;
+       int vc;
+       vecs_t **svp;
+       int i = 0;
 
 #define VEC_FMT "      %-20.20s  %-.50s\n"
 
-       for (vec = vec_list; vec->vec; vec++) {
-               printf(VEC_FMT, vec->name, vec->desc);
-               for (ap = vec->vec->args; ap && ap->argstring; ap++) {
+       /* Get a count from both the vec (normal) and the svec (csv) lists */
+
+       extern size_t nstyles;
+       vc = sizeof vec_list / sizeof vec_list[0] -1 + nstyles;
+
+       svp = xcalloc(vc, sizeof(style_vecs_t *));
+
+       /* Normal vecs are easy; populate the first part of the array. */
+       for (vec = vec_list; vec->vec; vec++, i++) {
+                       svp[i] = vec;
+       }
+       /* Walk the style list, parse the entries, dummy up a "normal" vec */
+       for (svec = style_list; svec->name; svec++, i++)  {
+               xcsv_read_internal_style(svec->style_buf);
+               svp[i] = xcalloc(1, sizeof **svp);
+               svp[i]->name = svec->name;
+               svp[i]->vec = svp[0]->vec; /* Interits xcsv opts */
+               svp[i]->desc = xcsv_file.description;
+       }
+
+       /* Now that we have everything in an array, alphabetize them */
+       qsort(svp, vc, sizeof(*svp), alpha);
+
+       for (i=0;i<vc;i++) {
+               printf(VEC_FMT, svp[i]->name, svp[i]->desc);
+               for (ap = svp[i]->vec->args; ap && ap->argstring; ap++) {
                printf("          %-18.18s    %-.50s %s\n",
                        ap->argstring, ap->helpstring,
                        (ap->argtype & ARGTYPE_REQUIRED)?"(required)":"");
                }
        }
-
-       /*
-        * Parse each internal style table in sequence to get the
-        * help strings from it.
-        */
-       for (svec = style_list; svec->name; svec++) {
-               xcsv_read_internal_style(svec->style_buf);
-               printf(VEC_FMT, svec->name, xcsv_file.description);
-       }
+               
+       return;
 }
 
 /*